package projet.camping.sevlets;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import projet.camping.domaine.Partie;
import projet.camping.usecases.GestionPartie;
import projet.camping.usecases.GestionUser;

@WebServlet(urlPatterns = "/logs.html")
public class Logs extends javax.servlet.http.HttpServlet implements
javax.servlet.Servlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1200046571726925827L;
	@EJB GestionUser user;
	@EJB GestionPartie uccPartie;
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.sendRedirect(resp.encodeRedirectURL("campingBattle.jsp"));
		return;
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession(false);
		if(session == null || (session!= null && session.getAttribute("login") == null)) {
			resp.sendRedirect(resp.encodeRedirectURL("campingBattle.jsp?fail"));
			return;
		}
		
		List<Partie> partiesFinie = uccPartie.getPartiesTerminees();
		req.setAttribute("partiesFinie", partiesFinie);
		
		RequestDispatcher rd = getServletContext().getNamedDispatcher("Logs");
		rd.forward(req, resp);
		
	}

	
	

}